package com.pei.controller;

import com.pei.pojo.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Controller
public class UserController {
    @RequestMapping("/getId")
    public void getId(HttpServletRequest request){
        String userId = request.getParameter("id");
        System.out.println(userId);

    }

    @RequestMapping("/getUserName")
    public void getUserNameAndId(String name,Integer id){
        System.out.println(name+""+id);
    }

    @RequestMapping("/getUserName2")
    public void getUserName(@RequestParam(value = "name",required = false,defaultValue = "pei") String name){
        System.out.println(name);
    }

    @RequestMapping("/restFul/{name}")
    public void getPathVariable(@PathVariable(value = "name") String username){
        System.out.println("username="+username);
    }

    @RequestMapping("/registerUser")
    public void registerUser(User user){
        System.out.println(user.toString());
    }
    @RequestMapping("/getBirthday")
    public void getBirthday(Date birthday){
        System.out.println(birthday);
    }
    @RequestMapping("/getBirByAnno")
    public void getBirByAnno(@DateTimeFormat(pattern = "yyyy-MM-dd")Date birthday){
        System.out.println(birthday);
    }

    @RequestMapping("/findOrderWithUser")
    public void findOrderWithUser(User user){
        String username = user.getUsername();
        String orderId = user.getOrder().getOrderId();
        System.out.println(username+""+orderId);
    }
}
